define(function(require, exports, module) {
	J = jQuery;
	require('bootstrap');
	require('bootstraponhover');
	require('plugins');
	require('validate');
	require('dmuploader');
	require('datetimepicker');
	require('datetimepicker.zh-CN');
	require('layer');
	layer.config({
	    path: '/assets/vendors/layer/' //layer.js所在的目录，可以是绝对目录，也可以是相对目录
	});
	var timenow = new Date().getTime();
	
	//用户登录后鼠标经过菜单
	$(".right-part").bootstrapDropdownOnHover();
	$(".menu-bar").bootstrapDropdownOnHover();

	//编辑用户信息
	$(".edit-label").on("click", function(){
		//console.log($(this).next(".holder").css("display") == "none");
		if($(this).next(".holder").css("display") == "none"){//如果当前隐藏  
			$(".edit-label").html("编辑");
			$(".holder").not($(this)).hide();
			$(this).html("收起");
			$(this).next(".holder").show();
	    }else{//否则  
	    	//$(".edit-label").html("收起");
			//$(".holder").not($(this)).show();
	    	$(this).html("编辑");
			$(this).next(".holder").hide();
	    }
	});
	
	
	$(".go-email").on("click", function(){
		$(this).parent().parent().parent().parent().parent().parent().parent().parent().find(".holder").hide();
		$(this).parent().parent().parent().parent().parent().parent().parent().prev(".edit-label").html("编辑");
		$("#_set_email").children(".edit-label").html("收起");
		$("#_set_email").children(".holder").show();
	});
	
	$(".form_datetime").datetimepicker({
		minView: "month", //选择日期后，不会再跳转去选择时分秒 
	    language:  'cn',
	    format: 'yyyy-mm-dd',
	    todayBtn:  1,
	    autoclose: 1,
	    todayHighlight: 1
    });
	
	//地区选择下拉菜单
	$('#contact_province').change(function () {
        $('#contact_city option:gt(0)').remove();
        $('#contact_area option:gt(0)').remove();
        var id=$(this).val();
        //alert(id);
        $.ajax({
            type: "post",
            dataType:"json",
            url: "/member/region.json",
            data: {"id":id},
            success: function (result) {
                var strocity = '';
                var datas = eval(result);
                $.each(datas, function(i,val){
                	strocity += "<option value='"+val.regionId+"' >"+val.regionName+"</option>";
                });  
                $('#contact_city').append(strocity);
            }
        })
    });	
	//县级下来菜单
	$('#contact_city').change(function () {
		$('#contact_area option:gt(0)').remove();
	    var id=$(this).val();
        $.ajax({
            type: "post",
            dataType:"json",
            url: "/member/region.json",
            data: {"id":id},
            success: function (result) {
                var stroarea = '';
                var datas = eval(result);
                $.each(datas, function(i,val){
                	stroarea += "<option value='"+val.regionId+"' >"+val.regionName+"</option>";
                });
                $('#contact_county').append(stroarea);
            }
         })
     });
	
	
	
	
	$("#user_url").on("blur", function(){
		var user_url=$("#user_url").val();
		if(!/^[0-9a-zA-Z_-]{3,20}$/.test(user_url)){
			$("#user_url_tp").html("域名格式为3-20位字母、数字、_、-");
			$("#user_url").focus();
			return false; 
		}
		if(!/(^([a-zA-Z_-]+)$)|(^[0-9_-]+$)|(^[0-9a-zA-Z_-]+$)/.test(user_url)){
			$("#user_url_tp").html("域名必须包含字母或者数字，不能用中文或者符号");
			$("#user_url").focus();
			return false; 
		}
		jQuery.ajax({
			type:"POST",
			url: "/member/domainname.json",
			data: {"user_url":user_url},
			dataType:"json",
			cache : false,
	        async: false, //ajax方法外可以调用变量
	        success : function(data) {
	        	if (data.code==0) {
	        		$("#user_url_tp").html("可以使用");
				}else{
					//layer.msg(data.message, {icon: 2});
					$("#user_url_tp").html("<span class=\"text-danger\">"+data.message+"</span>");
					return false;
				}
	        }
	    });
	});
	
	$(".settings-submit-btn").on("click",function(){
		var nickname = $("#nickname").val();
		var sex = $('input:radio[name="sex"]:checked').val();
		var province = $("#contact_province").val();
		var city = $("#contact_city").val();
		var county = $("#contact_county").val();
		var birthdate = $("#dtp_input1").val();
		var job = $("#job").val();
		var blog = $("#blog").val();
		var about = $("#about").val();
	
		$.ajax({
			url: "/member/profile.json?"+timenow,
			data: {"nickname":nickname,"sex":sex,"province":province,"city":city,"county":county,"birthdate":birthdate,"job":job,"blog":blog,"about":about},
    		dataType: "json",
    		type :  "POST",
    		cache : false,
    		async: false,
    		error : function(i, g, h) {
    			layer.msg('发送错误', {icon: 2});
    		},
    		success: function(data){	
    			if(data.code>=0){
    				layer.msg("提交成功！", {icon: 1});
    				window.location.reload();
    				return false;
    			}else{
					if(data.message!=''){
						layer.msg(data.message, {icon: 2});
						return false;
					}
				}
          	}
    	});
		return false;
	});
	
});